package com.itboye.lottery.retrofit;


import android.util.Log;

import com.itboye.lottery.bean.AddressBean;
import com.itboye.lottery.bean.AppConfigBean;
import com.itboye.lottery.bean.BalanceBean;
import com.itboye.lottery.bean.BetBean;
import com.itboye.lottery.bean.BetDetailBean;
import com.itboye.lottery.bean.BetZqDetailBean;
import com.itboye.lottery.bean.ColorBallPrizeHisBean;
import com.itboye.lottery.bean.FindBean;
import com.itboye.lottery.bean.FollowIndexBean;
import com.itboye.lottery.bean.FollowOrderDetailBean;
import com.itboye.lottery.bean.HistoryPrizeBean;
import com.itboye.lottery.bean.HotPeoleDetail;
import com.itboye.lottery.bean.IndexDataBean;
import com.itboye.lottery.bean.JinEDetail;
import com.itboye.lottery.bean.MessageBean;
import com.itboye.lottery.bean.MyFollowDetailBean;
import com.itboye.lottery.bean.NoticeBean;
import com.itboye.lottery.bean.OrderBean;
import com.itboye.lottery.bean.OutWrapBean;
import com.itboye.lottery.bean.PaySupportBean;
import com.itboye.lottery.bean.PeopleBean;
import com.itboye.lottery.bean.UserDataBean;
import com.itboye.lottery.bean.ZhuiHaoDetailBean;
import com.itboye.lottery.bean.ZqMatchDataCheck;
import com.itboye.lottery.retrofit.subscriber.CommonSubscriber;
import com.itboye.lottery.utils.Const;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import rx.Observable;
import rx.Subscriber;

/**
 * Created by YJY on 2017/10/13.
 */
public class RetrofitMethod extends RxMethod {

    private RetrofitInterface retrofitInterface;

    /**
     * 获取RetrofitHelper对象的单例
     */
    private static class Singleton {
        private static final RetrofitMethod INSTANCE = new RetrofitMethod();
    }

    public static RetrofitMethod getInstance() {
        return Singleton.INSTANCE;
    }

    private RetrofitMethod() {
        Log.v("url", Const.Companion.getAPI_URL());
        Retrofit retrofit = new Retrofit.Builder()
                .client(OkHttpManager.getClient().getOkHttp())

                .addConverterFactory(ResponseConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(Const.Companion.getAPI_URL())
                .build();
        retrofitInterface = retrofit.create(RetrofitInterface.class);
    }

    public void isRegister(CommonSubscriber<HttpResponse<UserDataBean>> subscriber, String wxcode) {
        Observable<HttpResponse<UserDataBean>> observable = retrofitInterface.isRegister(wxcode);
        onSubscribe(observable, subscriber);
    }


    //登录/注册
    public void wxLogin(Subscriber<HttpResponse<UserDataBean>> subscriber, String wxCode, String phone, String invite_code, String mobileCode) {
        Observable<HttpResponse<UserDataBean>> observable = retrofitInterface.login(wxCode, phone, invite_code, mobileCode);
        onSubscribe(observable, subscriber);
    }

    //登录/注册
    public void updateUserInfo(Subscriber<HttpResponse<String>> subscriber, String code) {
        Observable<HttpResponse<String>> observable = retrofitInterface.updateUserInfo(code);
        onSubscribe(observable, subscriber);
    }


    public void sendCode(CommonSubscriber<HttpResponse<String>> subscriber, int type, String phone) {
        Observable<HttpResponse<String>> observable = retrofitInterface.sendCode(type, phone);
        onSubscribe(observable, subscriber);
    }

    public void bindPhone(CommonSubscriber<HttpResponse<String>> subscriber, String phone, String code) {
        Observable<HttpResponse<String>> observable = retrofitInterface.bindPhone(phone, code);
        onSubscribe(observable, subscriber);
    }

    public void updatePhone(CommonSubscriber<HttpResponse<String>> subscriber, String phone, String code) {
        Observable<HttpResponse<String>> observable = retrofitInterface.updatePhone(phone, code);
        onSubscribe(observable, subscriber);
    }

    public void uploadAvatar(CommonSubscriber<HttpResponse<String>> subscriber, File file) {
        RequestBody requestFile =
                RequestBody.create(MediaType.parse("image/jpg"), file);
        MultipartBody.Part photoPart = MultipartBody.Part.createFormData("avatar", file.getName(),
                requestFile);
        Observable<HttpResponse<String>> observable = retrofitInterface.uploadAvatar(photoPart);
        onSubscribe(observable, subscriber);
    }

    public void homeIndex(CommonSubscriber<HttpResponse<IndexDataBean>> subscriber) {
        Observable<HttpResponse<IndexDataBean>> observable = retrofitInterface.homeIndex();
        onSubscribe(observable, subscriber);
    }

    public void getBetList(CommonSubscriber<HttpResponse<List<BetBean>>> subscriber, int type, int page) {
        Observable<HttpResponse<List<BetBean>>> observable = retrofitInterface.getBetList(type, page);
        onSubscribe(observable, subscriber);
    }

    public void feedback(CommonSubscriber<HttpResponse<String>> subscriber, String content) {
        Observable<HttpResponse<String>> observable = retrofitInterface.feedback(content);
        onSubscribe(observable, subscriber);
    }

    public void messageQuery(CommonSubscriber<HttpResponse<List<MessageBean>>> subscriber, int mParam1, int page) {
        Observable<HttpResponse<List<MessageBean>>> observable = retrofitInterface.messageQuery(mParam1, page);
        onSubscribe(observable, subscriber);
    }

    public void getAddressList(CommonSubscriber<HttpResponse<AddressBean>> subscriber, String addressId) {
        Observable<HttpResponse<AddressBean>> observable = retrofitInterface.getAddressList(addressId);
        onSubscribe(observable, subscriber);
    }

    public void updateAddress(CommonSubscriber<HttpResponse<String>> subscriber, String address_id, String consigneeName, String consigneeMobile, String province, String city, String district, String pcd, String isDefault) {
        Observable<HttpResponse<String>> observable = retrofitInterface.updateAddress(address_id, consigneeName, consigneeMobile, province, city, district, pcd, isDefault);
        onSubscribe(observable, subscriber);
    }

    public void addAddress(CommonSubscriber<HttpResponse<String>> subscriber, String consigneeName, String consigneeMobile, String province, String city, String district, String pcd, String isDefault) {
        Observable<HttpResponse<String>> observable = retrofitInterface.addAddress(consigneeName, consigneeMobile, province, city, district, pcd, isDefault);
        onSubscribe(observable, subscriber);
    }

    public void deleteAddress(CommonSubscriber<HttpResponse<String>> subscriber, String address_id) {
        Observable<HttpResponse<String>> observable = retrofitInterface.deleteAddress(address_id);
        onSubscribe(observable, subscriber);
    }

    public void chooseAddress(CommonSubscriber<HttpResponse<String>> subscriber, String addressId) {
        Observable<HttpResponse<String>> observable = retrofitInterface.chooseAddress(addressId);
        onSubscribe(observable, subscriber);
    }


    public void getWithdrawalBalance(CommonSubscriber<HttpResponse<BalanceBean>> subscriber) {
        Observable<HttpResponse<BalanceBean>> observable = retrofitInterface.getWithdrawalBalance();
        onSubscribe(observable, subscriber);
    }


    public void colorBallPrizeHistory(CommonSubscriber<HttpResponse<ColorBallPrizeHisBean>> subscriber) {
        Observable<HttpResponse<ColorBallPrizeHisBean>> observable = retrofitInterface.colorBallPrizeHistory();
        onSubscribe(observable, subscriber);
    }

    public void daLeTouPrizeHistory(CommonSubscriber<HttpResponse<ColorBallPrizeHisBean>> subscriber) {
        Observable<HttpResponse<ColorBallPrizeHisBean>> observable = retrofitInterface.daLeTouPrizeHistory();
        onSubscribe(observable, subscriber);
    }

    public void createOrderForColorBall(CommonSubscriber<HttpResponse<OrderBean>> subscriber, String num, int multiple, String push_number, int is_rand, int is_stop, int stop_money) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.createOrderForColorBall(num, multiple, push_number, is_rand, is_stop, stop_money);
        onSubscribe(observable, subscriber);
    }

    public void createOrderForDaLeTou(CommonSubscriber<HttpResponse<OrderBean>> subscriber, String num, int multiple, String push_number, int is_rand, int is_stop, int stop_money) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.createOrderForDaLeTou(num, multiple, push_number, is_rand, is_stop, stop_money);
        onSubscribe(observable, subscriber);
    }

    public void paySupport(CommonSubscriber<HttpResponse<List<PaySupportBean>>> subscriber) {
        Observable<HttpResponse<List<PaySupportBean>>> observable = retrofitInterface.paySupport();
        onSubscribe(observable, subscriber);
    }

    public void geFootBallMatch(CommonSubscriber<HttpResponse<Object>> subscriber) {
        Observable<HttpResponse<Object>> observable = retrofitInterface.geFootBallMatch();
        onSubscribe(observable, subscriber);
    }

    public void zqCreateOrder(CommonSubscriber<HttpResponse<OrderBean>> subscriber, String num, String origin_num, int multiple, String passType) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.zqCreateOrder(num, origin_num, multiple, passType, "smart");
        onSubscribe(observable, subscriber);
    }

    public void lqCreateOrder(CommonSubscriber<HttpResponse<OrderBean>> subscriber, String num, String origin_num, int multiple, String passType) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.lqCreateOrder(num, origin_num, multiple, passType, "smart");
        onSubscribe(observable, subscriber);
    }

    public void pay(CommonSubscriber<HttpResponse<String>> subscriber, String sn, double amount) {

        Observable<HttpResponse<String>> observable = retrofitInterface.pay(sn, amount);
        onSubscribe(observable, subscriber);
    }


//    public void chongzhi(CommonSubscriber<HttpResponse<OrderBean>> subscriber, double money) {
//        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.chongzhi(money);
//        onSubscribe(observable, subscriber);
//    }

    public void betShuZiCaiDetail(CommonSubscriber<HttpResponse<BetDetailBean>> subscriber, String sn) {
        Observable<HttpResponse<BetDetailBean>> observable = retrofitInterface.betShuZiCaiDetail(sn);
        onSubscribe(observable, subscriber);
    }

    public void betZqCaiDetail(CommonSubscriber<HttpResponse<BetZqDetailBean>> subscriber, String id) {
        Observable<HttpResponse<BetZqDetailBean>> observable = retrofitInterface.betZqCaiDetail(id);
        onSubscribe(observable, subscriber);
    }

    public void tixianShenQing(CommonSubscriber<HttpResponse<String>> subscriber, String money, String account, String account_type, String owner_name, String bank_branch_address) {
        Observable<HttpResponse<String>> observable = retrofitInterface.tixianShenQing(money, account, account_type, owner_name, bank_branch_address);
        onSubscribe(observable, subscriber);
    }

    public void mingxi(CommonSubscriber<HttpResponse<ArrayList<JinEDetail>>> subscriber, int type, int page) {
        Observable<HttpResponse<ArrayList<JinEDetail>>> observable = retrofitInterface.mingxi(type, page);
        onSubscribe(observable, subscriber);
    }


    public void getNotice(CommonSubscriber<HttpResponse<NoticeBean>> subscriber) {
        Observable<HttpResponse<NoticeBean>> observable = retrofitInterface.getNotice();
        onSubscribe(observable, subscriber);
    }

    public void getNoticeDetail(CommonSubscriber<HttpResponse<NoticeBean.NoticeItem>> subscriber, String id) {
        Observable<HttpResponse<NoticeBean.NoticeItem>> observable = retrofitInterface.getNoticeDetail(id);
        onSubscribe(observable, subscriber);
    }


    public void getNoticeZqDetail(CommonSubscriber<HttpResponse<ArrayList<NoticeBean.NoticeItem>>> subscriber, String ball_type, long open_time) {
        Observable<HttpResponse<ArrayList<NoticeBean.NoticeItem>>> observable = retrofitInterface.getNoticeZqDetail(ball_type, open_time);
        onSubscribe(observable, subscriber);
    }


    public void getHistoryPrize(CommonSubscriber<HttpResponse<HistoryPrizeBean>> subscriber) {
        Observable<HttpResponse<HistoryPrizeBean>> observable = retrofitInterface.getHistoryPrize();
        onSubscribe(observable, subscriber);
    }

    public void getSsqHistoryPrize(CommonSubscriber<HttpResponse<HistoryPrizeBean>> subscriber) {
        Observable<HttpResponse<HistoryPrizeBean>> observable = retrofitInterface.getSsqHistoryPrize();
        onSubscribe(observable, subscriber);
    }


    public void getAvailableBalance(CommonSubscriber<HttpResponse<Double>> subscriber) {
        Observable<HttpResponse<Double>> observable = retrofitInterface.getAvailableBalance();
        onSubscribe(observable, subscriber);
    }


    public void getPlayCenter(CommonSubscriber<HttpResponse<ArrayList<FindBean>>> subscriber) {
        Observable<HttpResponse<ArrayList<FindBean>>> observable = retrofitInterface.getPlayCenter();
        onSubscribe(observable, subscriber);
    }


    public void getNews(CommonSubscriber<HttpResponse<ArrayList<FindBean>>> subscriber, int page) {
        Observable<HttpResponse<ArrayList<FindBean>>> observable = retrofitInterface.getNews(page);
        onSubscribe(observable, subscriber);
    }

    public void getNewsNotice(CommonSubscriber<HttpResponse<ArrayList<FindBean>>> subscriber, int page) {
        Observable<HttpResponse<ArrayList<FindBean>>> observable = retrofitInterface.getNewsNotice(page);
        onSubscribe(observable, subscriber);
    }

    public void getAtivities(CommonSubscriber<HttpResponse<ArrayList<FindBean>>> subscriber, int page) {
        Observable<HttpResponse<ArrayList<FindBean>>> observable = retrofitInterface.getAtivities(page);
        onSubscribe(observable, subscriber);
    }

    public void faqigendan(CommonSubscriber<HttpResponse<OrderBean>> subscriber, int lottery_type, String num, String orignNum, int multiple, String pass_type, int type, int public_type, String reason, String low_amount, String ensure_odds) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.faqigendan(lottery_type, num, orignNum, multiple, pass_type, type, public_type, reason, low_amount, ensure_odds);
        onSubscribe(observable, subscriber);
    }


    public void getFollowIndex(CommonSubscriber<HttpResponse<FollowIndexBean>> subscriber, int sort, int page, int page_size, int is_follow) {
        Observable<HttpResponse<FollowIndexBean>> observable = retrofitInterface.getFollowIndex(sort, page, page_size, is_follow);
        onSubscribe(observable, subscriber);
    }


    public void getHotPeopleList(CommonSubscriber<HttpResponse<ArrayList<PeopleBean>>> subscriber, int page, int pageSize) {
        Observable<HttpResponse<ArrayList<PeopleBean>>> observable = retrofitInterface.getHotPeopleList(page, pageSize);
        onSubscribe(observable, subscriber);
    }

    public void followCase(CommonSubscriber<HttpResponse<OrderBean>> subscriber, int plan_id, int num) {
        Observable<HttpResponse<OrderBean>> observable = retrofitInterface.followCase(plan_id, num);
        onSubscribe(observable, subscriber);
    }

    public void getHotPeopleDetail(CommonSubscriber<HttpResponse<HotPeoleDetail>> subscriber, String hotPeopleId, int type, int page, int size) {
        Observable<HttpResponse<HotPeoleDetail>> observable = retrofitInterface.getHotPeopleDetail(hotPeopleId, type, page, size);
        onSubscribe(observable, subscriber);
    }

    public void myGenDan(CommonSubscriber<HttpResponse<ArrayList<BetBean>>> subscriber, int type, int page, int size) {
        Observable<HttpResponse<ArrayList<BetBean>>> observable = retrofitInterface.myGenDan(type, page, size);
        onSubscribe(observable, subscriber);
    }


    public void myTuiJian(CommonSubscriber<HttpResponse<ArrayList<BetBean>>> subscriber, int type, int page, int size) {
        Observable<HttpResponse<ArrayList<BetBean>>> observable = retrofitInterface.myTuiJian(type, page, size);
        onSubscribe(observable, subscriber);
    }

    public void getDaShenFollowDetail(CommonSubscriber<HttpResponse<FollowOrderDetailBean>> subscriber, String orderId) {
        Observable<HttpResponse<FollowOrderDetailBean>> observable = retrofitInterface.getDaShenFollowDetail(orderId);
        onSubscribe(observable, subscriber);
    }

    public void getFollowDetail(CommonSubscriber<HttpResponse<MyFollowDetailBean>> subscriber, String orderId, String lUid) {
        Observable<HttpResponse<MyFollowDetailBean>> observable = retrofitInterface.getFollowDetail(orderId, lUid);
        onSubscribe(observable, subscriber);
    }

    public void getFaDanDetail(CommonSubscriber<HttpResponse<FollowOrderDetailBean>> subscriber, String orderId) {
        Observable<HttpResponse<FollowOrderDetailBean>> observable = retrofitInterface.getFaDanDetail(orderId);
        onSubscribe(observable, subscriber);
    }

    public void newsDetail(CommonSubscriber<HttpResponse<FindBean>> subscriber, String articalId) {
        Observable<HttpResponse<FindBean>> observable = retrofitInterface.newsDetail(articalId);
        onSubscribe(observable, subscriber);
    }

    public void huoDongDetail(CommonSubscriber<HttpResponse<FindBean>> subscriber, String articalId) {
        Observable<HttpResponse<FindBean>> observable = retrofitInterface.huoDongDetail(articalId);
        onSubscribe(observable, subscriber);
    }

    public void gongGaoDetail(CommonSubscriber<HttpResponse<FindBean>> subscriber, String articalId) {
        Observable<HttpResponse<FindBean>> observable = retrofitInterface.gongGaoDetail(articalId);
        onSubscribe(observable, subscriber);
    }


    public void getZhuiHaoList(CommonSubscriber<HttpResponse<ArrayList<BetBean>>> subscriber, int page) {
        Observable<HttpResponse<ArrayList<BetBean>>> observable = retrofitInterface.getZhuiHaoList(page);
        onSubscribe(observable, subscriber);
    }

    public void getZhuiHaoDetail(CommonSubscriber<HttpResponse<ZhuiHaoDetailBean>> subscriber, String id) {
        Observable<HttpResponse<ZhuiHaoDetailBean>> observable = retrofitInterface.getZhuiHaoDetail(id);
        onSubscribe(observable, subscriber);
    }

    public void getAppConfig(CommonSubscriber<HttpResponse<ArrayList<AppConfigBean>>> subscriber) {
        Observable<HttpResponse<ArrayList<AppConfigBean>>> observable = retrofitInterface.getAppConfig();
        onSubscribe(observable, subscriber);
    }


    public void getMyAttentionList(CommonSubscriber<HttpResponse<OutWrapBean>> subscriber, int page, int pageSize, int follow) {
        Observable<HttpResponse<OutWrapBean>> observable = retrofitInterface.getMyAttentionList(page, pageSize, follow);
        onSubscribe(observable, subscriber);
    }

    public void follow(CommonSubscriber<HttpResponse<String>> subscriber, int id, int status) {
        Observable<HttpResponse<String>> observable = retrofitInterface.follow(id, status);
        onSubscribe(observable, subscriber);
    }

    public void getMyLotteryFragmentData(CommonSubscriber<HttpResponse<UserDataBean>> subscriber) {
        Observable<HttpResponse<UserDataBean>> observable = retrofitInterface.getMyLotteryFragmentData();
        onSubscribe(observable, subscriber);
    }

    public void getFootBallMathDataCheck(CommonSubscriber<HttpResponse<ZqMatchDataCheck>> subscriber, String num, int multiple, String free_pass) {
        Observable<HttpResponse<ZqMatchDataCheck>> observable = retrofitInterface.getFootBallMathDataCheck(num, 1, free_pass);
        onSubscribe(observable, subscriber);
    }

    public void getBasketballMathDataCheck(CommonSubscriber<HttpResponse<ZqMatchDataCheck>> subscriber, String num, int multiple, String free_pass) {
        Observable<HttpResponse<ZqMatchDataCheck>> observable = retrofitInterface.getBasketballMathDataCheck(num, 1, free_pass);
        onSubscribe(observable, subscriber);
    }


    public void getBasketballMatch(CommonSubscriber<HttpResponse<Object>> subscriber) {
        Observable<HttpResponse<Object>> observable = retrofitInterface.getBasketballMatch();
        onSubscribe(observable, subscriber);
    }

    public void zfbH5Pay(CommonSubscriber<HttpResponse<String>> subscriber, String sn, String coupon_id, String payType, String return_url) {
        Observable<HttpResponse<String>> observable = retrofitInterface.zfbH5GrPay(sn, coupon_id, payType, return_url);
        onSubscribe(observable, subscriber);
    }

    public void chongzhiByFs(CommonSubscriber<HttpResponse<String>> subscriber, String sn, double amount, String oauth, String pay_type, String return_url) {
        Observable<HttpResponse<String>> observable = retrofitInterface.chongzhiByGr(sn, amount, oauth, pay_type, return_url);
        onSubscribe(observable, subscriber);
    }

    public void optimize(CommonSubscriber<HttpResponse<ArrayList<ArrayList<String>>>> subscriber, String type, float totalMoney, String bonus) {
        Observable<HttpResponse<ArrayList<ArrayList<String>>>> observable = retrofitInterface.optimize(type, totalMoney, bonus);
        onSubscribe(observable, subscriber);
    }

    public void loginByPhone(CommonSubscriber<HttpResponse<UserDataBean>> subscriber, String phone, String code) {
        Observable<HttpResponse<UserDataBean>> observable = retrofitInterface.loginByPhone(phone, code);
        onSubscribe(observable, subscriber);
    }

    public void registerByPhone(CommonSubscriber<HttpResponse<UserDataBean>> subscriber, String phone, String code, String inviteCode) {
        Observable<HttpResponse<UserDataBean>> observable = retrofitInterface.registerByPhone(phone, code, inviteCode);
        onSubscribe(observable, subscriber);
    }


}
